//
//  CJSStoryCell.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/25.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "CJSStoryCell.h"
#import "CJSDetail_list.h"
#import "UIImageView+WebCache.h"
#import "WSTools.h"
#import "GSYImageView.h"

@interface CJSStoryCell ()

@property (nonatomic, retain) UIImageView *contentImageView;

@property (nonatomic, retain) UIImageView *hornView;

@property (nonatomic, retain) UILabel *contentLabel;

@property (nonatomic, retain) GSYImageView *occupyImage;

@end

@implementation CJSStoryCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
        [self createSubViews];
    }
    
    return self;
}

- (void)createSubViews {
    
    self.occupyImage = [[GSYImageView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, SCREEN_WIDTH * 798 / 1200.0)];
    self.occupyImage.layer.cornerRadius = 5;
    self.occupyImage.layer.masksToBounds = YES;
    [self.contentView addSubview:self.occupyImage];
    
    self.contentImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, SCREEN_WIDTH * 798 / 1200.0)];
    self.contentImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.contentImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:_contentImageView];
    
    self.hornView = [[UIImageView alloc] initWithFrame:CGRectMake(30, self.contentImageView.frame.size.height - 6, 12, 6)];
    [self.contentImageView addSubview:self.hornView];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.contentImageView.frame.size.height + 5, self.contentImageView.frame.size.width, 0)];
    self.contentLabel.font = [UIFont systemFontOfSize:15];
    self.contentLabel.textColor = [UIColor colorWithRed:0.28 green:0.28 blue:0.28 alpha:1];
    self.contentLabel.numberOfLines = 0;
    [self addSubview:_contentLabel];

}

- (void)setDetail_list:(CJSDetail_list *)detail_list {
    _detail_list = detail_list;
    self.contentImageView.frame = CGRectMake(15, 0, SCREEN_WIDTH - 30, SCREEN_WIDTH * self.detail_list.photo_height / self.detail_list.photo_width);
    self.occupyImage.frame = self.contentImageView.frame;
    [self.contentImageView sd_setImageWithURL:[NSURL URLWithString:_detail_list.photo] placeholderImage:[UIImage imageNamed:@""]];
    
    self.hornView.frame = CGRectMake(30, self.contentImageView.frame.size.height - 6, 12, 6);
    
    self.contentLabel.frame = CGRectMake(15, self.contentImageView.frame.size.height + 5, self.contentImageView.frame.size.width, 0);
    self.contentLabel.text = _detail_list.text;
    self.hornView.image = [UIImage imageNamed:@"up_triangle"];
    CGRect frame = self.contentLabel.frame;
    frame.size.height = [WSTools heightForContent:_detail_list.text size:15];
    self.contentLabel.frame = frame;
    
}

- (UIImage *)getImage {
    
    UIImage *cachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:_detail_list.photo];
    
    return cachedImage;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
